package com.hjq.fcloud.other

import android.text.TextUtils
import android.widget.TextView
import com.alibaba.fastjson.JSON
import com.google.gson.internal.LinkedTreeMap
import com.hjq.fcloud.ktx.ViewKtx.setVisibility
import com.hjq.fcloud.utils.Logger

/**
 * 设置列表签约样式
 */
object SignStatusHelper {

    //会议纪要会签
    const val MENU_ID_MEETING = "30000"

    /**
     * 设置列表签约样式，点击跳转签约页面
     */
    fun setRightStatusFlowStyle(
        statusFlowTv: TextView,
        obj: LinkedTreeMap<String, Any>,
        menuId: String?,
        cakllback: () -> Unit
    ) {
        if (!TextUtils.isEmpty(menuId)) {
            if (menuId.equals(MENU_ID_MEETING) && showSignViewByMeeting(obj)) {
                setSignViewState(statusFlowTv, cakllback)
            } else if (showSignViewByOther(obj)) {
                setSignViewState(statusFlowTv, cakllback)
            }
        }
    }


    private fun setSignViewState(statusFlowTv: TextView, cakllback: () -> Unit) {
        statusFlowTv.setVisibility(true)
        statusFlowTv.setText("签约")
        statusFlowTv.setOnClickListener { cakllback() }
    }

    private fun showSignViewByOther(obj: LinkedTreeMap<String, Any>): Boolean {
        var flow_status = obj.get("flow_status")?.toString()
        //6，9表示自己签了,3表示会签中
        return flow_status.equals("3")
    }

    private fun showSignViewByMeeting(obj: LinkedTreeMap<String, Any>): Boolean {
        var statusFlow = obj.get("status_flow")?.toString()
        var status = obj.get("status")?.toString()
        return (statusFlow.equals("4") && !status.equals("5") && !status.equals("6"))
    }
}